<?php

namespace app\service;

use TencentCloud\Common\Credential;
use TencentCloud\Common\Profile\ClientProfile;
use TencentCloud\Common\Profile\HttpProfile;
use TencentCloud\Common\Exception\TencentCloudSDKException;
use TencentCloud\Trtc\V20190722\TrtcClient;
use TencentCloud\Trtc\V20190722\Models\DismissRoomRequest;

class TrtcService
{
    /**
     * 解散房间s
     * @param int $thumb
     * @param int $water
     * @return \think\response\Json
     */
    public static function free($RoomId = '')
    {
        if(!$RoomId){
            return;
        }
        self::free1($RoomId);
        self::free2($RoomId);
    }
    public static function free1($RoomId = '')
    {
        try {
            // 实例化一个认证对象，入参需要传入腾讯云账户secretId，secretKey,此处还需注意密钥对的保密
            // 密钥可前往https://console.cloud.tencent.com/cam/capi网站进行获取
            $cred = new Credential(getenv('SECRET_ID'), getenv('SECRET_KEY'));
            // 实例化一个http选项，可选的，没有特殊需求可以跳过
            $httpProfile = new HttpProfile();
            $httpProfile->setEndpoint("trtc.tencentcloudapi.com");

            // 实例化一个client选项，可选的，没有特殊需求可以跳过
            $clientProfile = new ClientProfile();
            $clientProfile->setHttpProfile($httpProfile);
            // 实例化要请求产品的client对象,clientProfile是可选的
            $client = new TrtcClient($cred, "ap-guangzhou", $clientProfile);

            // 实例化一个请求对象,每个接口都会对应一个request对象
            $req = new DismissRoomRequest();
            
            $params = array(
                'SdkAppId'  => intval(getenv('TLS_APPID')),
                'RoomId'    => intval($RoomId)
            );
            $req->fromJsonString(json_encode($params));

            // 返回的resp是一个DismissRoomResponse的实例，与请求对象对应
            $resp = $client->DismissRoom($req);

            return $resp->toJsonString();
        }
        catch(TencentCloudSDKException $e) {
            return $e->getMessage();
        }
    }
    public static function free2($RoomId = '')
    {
        try {
            // 实例化一个认证对象，入参需要传入腾讯云账户secretId，secretKey,此处还需注意密钥对的保密
            // 密钥可前往https://console.cloud.tencent.com/cam/capi网站进行获取
            $cred = new Credential(getenv('RELANG_SECRET_ID'), getenv('RELANG_SECRET_KEY'));
            // 实例化一个http选项，可选的，没有特殊需求可以跳过
            $httpProfile = new HttpProfile();
            $httpProfile->setEndpoint("trtc.tencentcloudapi.com");

            // 实例化一个client选项，可选的，没有特殊需求可以跳过
            $clientProfile = new ClientProfile();
            $clientProfile->setHttpProfile($httpProfile);
            // 实例化要请求产品的client对象,clientProfile是可选的
            $client = new TrtcClient($cred, "ap-guangzhou", $clientProfile);

            // 实例化一个请求对象,每个接口都会对应一个request对象
            $req = new DismissRoomRequest();
            
            $params = array(
                'SdkAppId'  => intval(getenv('RELANG_TLS_APPID')),
                'RoomId'    => intval($RoomId)
            );
            $req->fromJsonString(json_encode($params));

            // 返回的resp是一个DismissRoomResponse的实例，与请求对象对应
            $resp = $client->DismissRoom($req);

            return $resp->toJsonString();
        }
        catch(TencentCloudSDKException $e) {
            return $e->getMessage();
        }
    }
}